package com.lly.schedule.dao.impl;

import com.lly.schedule.dao.BaseDao;
import com.lly.schedule.dao.SysScheduleDao;
import com.lly.schedule.pojo.SysSchedule;

import java.util.List;

public class SysScheduleDaoImpl extends BaseDao implements SysScheduleDao {
    @Override
    public int addSchedule(SysSchedule schedule) throws Exception {
        String sql = "insert into sys_schedule(uid,title,completed) values(?,?,?)";
        int rows = baseUpdate(sql, schedule.getUid(), schedule.getTitle(), schedule.getCompleted());
        return rows;
    }

    @Override
    public List<SysSchedule> findall() throws Exception {
        String sql = "select sid,uid,title,completed from sys_schedule";
        List<SysSchedule> sysSchedules = baseQuery(SysSchedule.class, sql);
        return sysSchedules;
    }

    @Override
    public int add(int uid) throws Exception {
        String sql = "insert into sys_schedule value(default,?,'请输入title',1)";
        return baseUpdate(sql, uid);
    }

    @Override
    public int update(SysSchedule sysSchedule) throws Exception {
        String sql ="update sys_schedule set title = ? ,completed =  ? where sid =?";
        return baseUpdate(sql,sysSchedule.getTitle(),sysSchedule.getCompleted(),sysSchedule.getSid());
    }

    @Override
    public void remove(int uid) throws Exception {
        String sql="delete from sys_schedule where sid = ?";
        baseUpdate(sql,uid);
    }
}
